<template>
<Row class="layout-content-body">

  <dtable :columnsList="columns" v-model="dataAll" :totals="total" 
  :busyName="busyName" :busyTable="busyTable"
  add check op delCheck flowstart editCheck @refresh="getall()"
   @add="add" @del="del" @edit="edit" @delList="delList" 
  :loading="loading"></dtable>
  <Modal title="选择模板" v-model="showTemp" :mask-closable="false" class-name="editm" @on-ok="asyncOK">
    <Form ref="editForm" :model="orderData" :label-width="80">
      <Form-item label="模板" prop="Partner">
        <Select v-model="orderData.temp" placeholder="请选择">
            <Option v-for="item  in templist" :value="item.Id" :key="item.Id">{{item.Name}}</Option>
        </Select>
      </Form-item>
    </Form>
  </Modal>
</Row>
</template>

<script>
import {
  timeFormat, currency
} from '@/common/filter'
import dtable from '@/components/table/etable.vue' //采用biztable
export default {
  data() {
    return {
      loading: false, //数据刷新遮罩层
      busyName:"销售订单",
      busyTable:"yjk_order",
      columns: [
        //多选框
        {
          title: '名称',
          key: 'Name',
          sortable: true
        },
        {
          title: '客户',
          key: 'CustName',
          sortable: true
        },
        {
          title: '金额',
          key: 'DiscountPrice',
          sortable: true,
          render: (h, params) => {
            return h('div', [
              h('strong', currency(params.row.DiscountPrice,"￥"))
            ]);
          }
        },
        {
          title: '说明',
          key: 'Remark',
          sortable: true,
        },
        {
          title: '责任人',
          key: 'Creater',
          sortable: true
        },
        {
          title: '创建时间',
          key: 'Ctime',
          sortable: true,
          render: (h, params) => {
            return h('div', [
              h('strong', timeFormat(params.row.Ctime))
            ]);
          }
        },
      ], //表格样式
      dataAll: [], //表格数据来源
      templist: [],
      dataShow: true, //是否显示表格数据查看表单
      showTemp: false,
      total: 0,
      orderData: {
        edit: false,
        temp: ''
      },
    }
  },
  components: {
    dtable,
  },
  computed: {

  },
  watch: {},
  methods: {
    getall() {
      this.loading = true
      this.$api.GetMyOrder().then(res => {
        if (!res.error) {
          console.debug(res)
          this.dataAll = res.Data
          if (this.dataAll) {
            this.total = (this.dataAll).length
          }
        } else {
          this.$Message.error(res.message)
        }
      })
      this.$api.getTemp().then(res => {
        if (!res.error) {
          this.templist = res.Data
        } else {
          this.$Message.error(res.message)
        }
      })
      this.loading = false;
    },
    edit(index) {
      console.log(index.Id)
      this.orderData.order = index
      this.orderData.edit = true
      this.$router.push({
        name: '销售订单明细',
        params: {
          orderData: this.orderData
        }
      })
    },
    add() {
      this.orderData.edit = false
      this.showTemp = true
    },
    asyncOK() {
      this.$router.push({
        name: '销售订单明细',
        params: {
          orderData: this.orderData
        }
      })
    },
    del(row) {
      this.$api.deleteOrder(row).then(res => {
        if (!res.error) {
          this.getall()
          this.$Message.success(res.message)
        } else {
          this.$Message.error(res.message, 4)
        }
      })
    },
    delList(row) {
      this.$api.deleteOrderList(row).then(res => {
        if (!res.error) {
          this.getall()
          this.$Message.success(res.message)
        } else {
          this.$Message.error(res.message, 4)
        }
      })
    },
    
  },
  mounted() {
    this.getall()
  }
}
</script>
